<?php

namespace common\models\customset;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\customset\CustomSet;

/**
 * CustomSetSearch represents the model behind the search form about `common\models\customset\CustomSet`.
 */
class CustomSetSearch extends CustomSet
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['set_id', 'limit_id', 'is_pay', 'price', 'versions'], 'integer'],
            [['title', 'keyword', 'intro', 'addtime', 'top_pic', 'succ_info', 'err_info', 'detail', 'token', 'tel', 'address', 'longitude', 'latitude', 'pay_name', 'follow', 'sms', 'fixphone'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = CustomSet::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'set_id' => $this->set_id,
            'limit_id' => $this->limit_id,
            'is_pay' => $this->is_pay,
            'price' => $this->price,
            'versions' => $this->versions,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'keyword', $this->keyword])
            ->andFilterWhere(['like', 'intro', $this->intro])
            ->andFilterWhere(['like', 'addtime', $this->addtime])
            ->andFilterWhere(['like', 'top_pic', $this->top_pic])
            ->andFilterWhere(['like', 'succ_info', $this->succ_info])
            ->andFilterWhere(['like', 'err_info', $this->err_info])
            ->andFilterWhere(['like', 'detail', $this->detail])
            ->andFilterWhere(['like', 'token', $this->token])
            ->andFilterWhere(['like', 'tel', $this->tel])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'longitude', $this->longitude])
            ->andFilterWhere(['like', 'latitude', $this->latitude])
            ->andFilterWhere(['like', 'pay_name', $this->pay_name])
            ->andFilterWhere(['like', 'follow', $this->follow])
            ->andFilterWhere(['like', 'sms', $this->sms])
            ->andFilterWhere(['like', 'fixphone', $this->fixphone]);

        return $dataProvider;
    }
}
